package com.system.manager.modules.authorized.entity;

import com.baomidou.mybatisplus.annotation.IdType;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;

import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.utils.MD5Utils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

/**
 * <p>
 *
 * </p>
 *
 * @author yxp
 * @since 2021-10-18
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "User对象", description = "")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户的主键")
    @TableId(value = "user_id", type = IdType.AUTO)
    private Integer userId;

    @ApiModelProperty(value = "用户帐号")
    private String userAccount;

    @ApiModelProperty(value = "用户名")
    private String name;

    @ApiModelProperty(value = "密码")
    private String password;

    // 解密后的密码
    private String deCodePswd;

    @ApiModelProperty(value = "手机号码")
    private String phone;

    @ApiModelProperty(value = "用户角色")
    private Integer role;

    @ApiModelProperty(value = "用户状态")
    private Integer status;

    @ApiModelProperty(value = "组织机构")
    private Integer organizationId;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    public String getDeCodePswd() {
        if (!StringUtils.isEmpty(password)) {
            String decodePswd = MD5Utils.decode(password);
            return decodePswd;
        }
        return deCodePswd;
    }


    public static Integer getRoleType(String role) {
        Integer type = SubjectType.valueTypeOf(role).getType();

        return type;
    }

}
